import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '控制台', icon: 'dashboard' }
    }]
  },

  {
    path: '/transfusion',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: '输血科工作站',
      icon: 'nested'
    },
    children: [
      {
        path: '/transfusion/blood-cure',
        component: () => import('@/views/transfusion/blood-cure/index'), // Parent router-view
        name: 'transfusion-blood-cure-index',
        meta: { title: '输血治疗' },
        children: [
          {
            path: 'index',
            component: () => import('@/views/transfusion/blood-cure/index/index'),
            name: 'transfusion-blood-cure-index-index',
            meta: { title: '单采治疗操作记录' }
          },
          {
            path: 'gather',
            component: () => import('@/views/transfusion/blood-cure/gather/index'),
            name: 'transfusion-blood-cure-gather-index',
            meta: { title: '治疗记录汇总表' }
          },
          {
            path: 'advice',
            component: () => import('@/views/transfusion/blood-cure/advice/index'),
            name: 'transfusion-blood-cure-advice-index',
            meta: { title: '临时医嘱本' }
          }
        ]
      },
      {
        path: '/transfusion/shift-changes',
        component: () => import('@/views/transfusion/shift-changes/index'), // Parent router-view
        name: 'transfusion-blood-cure-index',
        meta: { title: '交接班管理' },
        children: [
          {
            path: 'day',
            component: () => import('@/views/transfusion/shift-changes/day/index'),
            name: 'transfusion-shift-changes-day-index',
            meta: { title: '白班' }
          },
          {
            path: 'night',
            component: () => import('@/views/transfusion/shift-changes/night/index'),
            name: 'transfusion-shift-changes-night-index',
            meta: { title: '夜班' }
          }
        ]
      },
      {
        path: '/transfusion/lab-test',
        component: () => import('@/views/transfusion/lab-test/index'), // Parent router-view
        name: 'transfusion-lab-test-index',
        meta: { title: '实验室检测' },
        children: [
          {
            path: 'hard-match-reg',
            component: () => import('@/views/transfusion/lab-test/hard-match-reg/index'),
            name: 'transfusion-lab-test-hard-match-reg-index',
            meta: { title: '疑难配血登记' }
          }
        ]
      },
      {
        path: '/transfusion/quality-control',
        component: () => import('@/views/transfusion/quality-control/index'), // Parent router-view
        name: 'transfusion-quality-control-index',
        meta: { title: '质量控制' },
        children: [
          {
            path: 'index',
            component: () => import('@/views/transfusion/quality-control/in-room/index'),
            name: 'transfusion-quality-control-index-room-index',
            meta: { title: '室内质量控制' }
          }
        ]
      },
      {
        path: '/transfusion/fee',
        component: () => import('@/views/transfusion/fee/index'), // Parent router-view
        name: 'transfusion-fee-index',
        meta: { title: '费用管理' },
        children: [
          {
            path: 'outpatient-service-charging',
            component: () => import('@/views/transfusion/fee/outpatient-service-charging/index'),
            name: 'transfusion-fee-outpatient-service-charging-index',
            meta: { title: '门诊病人手工划价' }
          },
          {
            path: 'outpatient-service-search',
            component: () => import('@/views/transfusion/fee/outpatient-service-search/index'),
            name: 'transfusion-fee-outpatient-service-search-index',
            meta: { title: '门诊病人费用查询' }
          },
          {
            path: 'in-hospital-charging',
            component: () => import('@/views/transfusion/fee/in-hospital-charging/index'),
            name: 'transfusion-fee-in-hospital-charging-index',
            meta: { title: '住院病人手工划价' }
          },
          {
            path: 'in-hospital-search',
            component: () => import('@/views/transfusion/fee/in-hospital-search/index'),
            name: 'transfusion-fee-in-hospital-search-index',
            meta: { title: '住院病人费用查询' }
          },
        ]
      },
      {
        path: '/transfusion/search',
        component: () => import('@/views/transfusion/search/index'), // Parent router-view
        name: 'transfusion-search-index',
        meta: { title: '信息查询' },
        children: [
          {
            path: 'check-result',
            component: () => import('@/views/transfusion/search/check-result/index'),
            name: 'transfusion-search-check-result-index',
            meta: { title: '患者检验结果查询' }
          },
          {
            path: 'patient-in-hospital',
            component: () => import('@/views/transfusion/search/patient-in-hospital/index'),
            name: 'transfusion-search-patient-in-hospital-index',
            meta: { title: '在院病人一览表' }
          },
          {
            path: 'blood-letting',
            component: () => import('@/views/transfusion/search/blood-letting/index'),
            name: 'transfusion-search-blood-letting-index',
            meta: { title: '发血统计' }
          },
          {
            path: 'blood-match',
            component: () => import('@/views/transfusion/search/blood-match/index'),
            name: 'transfusion-search-blood-match-index',
            meta: { title: '配血统计' }
          },
          {
            path: 'patient-use-blood',
            component: () => import('@/views/transfusion/search/patient-use-blood/index'),
            name: 'transfusion-search-patient-use-blood-index',
            meta: { title: '病人用血量排序查询' }
          },
          {
            path: 'untoward',
            component: () => import('@/views/transfusion/search/untoward/index'),
            name: 'transfusion-search-untoward-index',
            meta: { title: '输血不良反应统计' }
          },
          {
            path: 'fee-outpatient-service',
            component: () => import('@/views/transfusion/search/fee-outpatient-service/index'),
            name: 'transfusion-search-fee-outpatient-service-index',
            meta: { title: '门诊医疗费用统计' }
          },
          {
            path: 'fee-in-hospital',
            component: () => import('@/views/transfusion/search/fee-in-hospital/index'),
            name: 'transfusion-search-fee-in-hospital-index',
            meta: { title: '住院医疗费用统计' }
          },
          {
            path: 'blood-outbound',
            component: () => import('@/views/transfusion/search/blood-outbound/index'),
            name: 'transfusion-search-blood-outbound-index',
            meta: { title: '出库血液查询' }
          },
          {
            path: 'blood-buy',
            component: () => import('@/views/transfusion/search/blood-buy/index'),
            name: 'transfusion-search-blood-buy-index',
            meta: { title: '外买血液查询' }
          }
        ]
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
